package com.quick.develop.flowable.framework.cmd;

import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.service.HistoricTaskService;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

import java.util.Date;

/**
 * @author junyuan.liu
 * @description:
 * @date 2022/8/14 13:40
 */
public class RecordTaskInfoChangeCmd extends NeedsActiveTaskCmd<Void> {

    private static final long serialVersionUID = 5596682456358893237L;

    public RecordTaskInfoChangeCmd(String taskId) {
        super(taskId);
    }

    @Override
    protected Void execute(CommandContext commandContext, TaskEntity taskEntity) {
        HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService(commandContext);
        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
        HistoricTaskInstanceEntity historicTaskInstanceEntity = historicTaskService.recordTaskInfoChange(taskEntity, new Date(), processEngineConfiguration);
        historicTaskService.updateHistoricTask(historicTaskInstanceEntity, false);
        return null;
    }
}
